package org.cid54.android.jshopper;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import org.cid54.android.jshopper.dao.DaoCallBackMethod;
import org.cid54.android.jshopper.dao.ItemDao;
import org.cid54.android.jshopper.dao.impl.ItemDaoImpl;

/**
 *
 * @author fgo
 */
public class NewItem extends Activity{

    private ItemDao itemDao = new ItemDaoImpl();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.new_item);

        final EditText editText = (EditText) this.findViewById(R.id.new_item_name_entry);

        Button saveBtn = (Button) this.findViewById(R.id.new_item_save_button);

        saveBtn.setOnClickListener(new OnClickListener() {

            public void onClick(View view) {

                String itemName = editText.getText().toString();

                itemDao.addItem(itemName, new DaoCallBackMethod<Boolean>() {

                    public void execute(Boolean t) {
                        if(t){
                            finish();
                        }
                    }
                });

            }
        });

    }

}
